<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="install/index/head :: header('DS-CMS系统安装')" />
</head>
<body>
<style type="text/css">
    .layui-table td, .layui-table th{text-align:left;}
    .layui-table tbody tr.no{background-color:#f00;color:#fff;}
</style>
<th:block th:include="install/index/head :: headerbody" />

<div class="install-box">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>最后一步</legend>
    </fieldset>
    <h1>请不要关闭此界面，程序正在安装。</h1>

    <div class="step-btns">
        <div class="layui-progress layui-progress-big" lay-filter="prg" lay-showPercent="true">
            <div class="layui-progress-bar" lay-percent="0%"></div>
        </div>
    </div>

    <img lay-src="https://img.xjh.me/random_img.php?return=302&type=bg" width="100%">
</div>

<th:block th:include="install/index/foot :: foot" />
<script type="text/javascript">
    layui.define(['element', 'flow','layer'], function(exports) {
        var element = layui.element;
        var  flow=layui.flow;
        var layer = layui.layer;
        var $ = layui.jquery

        flow.lazyimg();

        element.progress('prg','0%');


        var n=0;
        var timer = setInterval(function(){
            n+=Math.ceil(Math.random()*10);
            if (n>100){
                n=100;
            }
            element.progress('prg', n+'%');
            $.ajax({
                type: "POST",
                url: 'test',
                dataType:'json',
                success: function(res) {
                    if(res.code==1 && res.msg=='安装完成'){
                        layer.open({
                            title: '成功'
                            ,content: res.msg,
                            yes: function(index){
                                window.location.href="/"
                            },
                        });
                        element.progress('prg', '100%');
                        clearInterval(timer)
                    }else if (res.code==0){
                        layer.open({
                            title: '安装错误'
                            ,content: res.msg
                        });
                        clearInterval(timer)
                    }

                },
                error:function (request) {
                    layer.open({
                        title: '错误'
                        ,content: '很抱歉，安装失败了，请手动重启程序'
                    });
                    clearInterval(timer)
                }
            });

        }, 3000)


        $.ajax({
            type: "POST",
            url: 'restart',
            dataType:'json',
            success: function(res) {
                if(res.code==0){
                    layer.open({
                        title: '提示'
                        ,content: res.msg
                    });
                }
            },
            error:function (request) {
                layer.open({
                    title: '错误'
                    ,content: '很抱歉，安装失败了，请手动重启程序'
                });

            }
        });




    })



</script>
</body>

</html>

